package com.sch.study.algorithm;

/**
 * User: hui_stone
 * Date: 2016/2/26 0026
 * Time: 上午 10:52
 */
public class BinarySearch {

    public static Integer midSearch(int[] array,int searchValue){

        int start = 0;
        int end = array.length -1;
        while(start<end){
            int mid = start+(end-start)/2;
            if(searchValue == array[mid]){
                return mid;
            }else if(searchValue<array[mid]){
                end = mid -1;
            }else{
                start = mid+1;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int[] array ={1,2,3,4,5,6,7};

        System.out.println(BinarySearch.midSearch(array, 6));
    }
}
